Skip to content

pthread: zero-fill .tbss when initializing thread TLS#78

Merged
Bryan Bayerdorffer (bryanb-h2) merged 1 commit into
masterfrom
tls-fix
Jul 22, 2026
Merged

pthread: zero-fill .tbss when initializing thread TLS#78
Bryan Bayerdorffer (bryanb-h2) merged 1 commit into
masterfrom
tls-fix

Conversation

@quic-k

@quic-k quic-k commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

pthread_create_common() copied the whole TLS image with memcpy, but the .tbss portion is NOBITS and has no valid source bytes -- it must be zeroed, not copied. As a result a new thread's .tbss inherited garbage.

Initialize TLS per the ELF spec: memcpy .tdata, then memset .tbss to zero, using the weak linker symbols __tdata_source/__tdata_size/ __tbss_size (they resolve to 0 on legacy non-picolibc links, making the change a no-op there).

pthread_create_common() copied the whole TLS image with memcpy, but the
.tbss portion is NOBITS and has no valid source bytes -- it must be
zeroed, not copied. As a result a new thread's .tbss inherited garbage.

Initialize TLS per the ELF spec: memcpy .tdata, then memset .tbss to
zero, using the weak linker symbols __tdata_source/__tdata_size/
__tbss_size (they resolve to 0 on legacy non-picolibc links, making the
change a no-op there).

Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

@bryanb-h2
Bryan Bayerdorffer (bryanb-h2) merged commit 2f9a3b3 into master Jul 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untested Mark untested PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants